import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'Home',
    redirect:'/login'

  },
  
  {
    path: '/about',
    name: 'About',
    redirect: '/welcome',
    component: () => import('../views/About.vue'),

    children:[
      {
        path: '/users',
        name: 'users',
        component: () => import('../views/home/users.vue')
      },
      {
        path: '/rights',
        name: 'rights',
        component: () => import('../views/home/rights.vue')
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import('../views/home/goods.vue')
      },
      {
        path: '/orders',
        name: 'orders',
        component: () => import('../views/home/orders.vue')
      },
      {
        path: '/reports',
        name: 'reports',
        component: () => import('../views/home/reports.vue')
      },
      {
        path: '/welcome',
        name: 'welcome',
        component: () => import('../views/home/welcome.vue')
      },
      {
        path: '/roles',
        name: 'roles',
        component: () => import('../views/home/roles.vue')
      },
      {
        path: '/params',
        name: 'params',
        component: () => import('../views/home/params.vue')
      },
      {
        path: '/categories',
        name: 'categories',
        component: () => import('../views/home/categories.vue')
      },
    ]
  },
  {
    path: '/',
    redirect:'/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/login.vue')
  },
]




const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenSter = window.localStorage.getItem('token')
  if (!tokenSter) return next('/login')
  next()
})
export default router